1 package jrre.instructionset.objects;
2
3 import jrre.*;
4 import jrre.types.*;
5 import jrre.classloader.classfile.pool_entries.*;
6
7 public class GetStatic extends jrre.instructionset.Instruction {
8
9 private int operandOne;
10 private int operandTwo;
11
12 public GetStatic(int operandOne, int operandTwo){
13
14 this.operandOne = operandOne;
15 this.operandTwo = operandTwo;
16
17 name = "getstatic "+operandOne+" "+operandTwo;
18 description = "pushes a field.";
19 length = 2;
20 }
21
22 /***
23 * Executes the <strong><code>getstatic</code></strong> instruction.
24 *
25 */
26 public void execute(){
27
28 int fieldIndex = (operandOne << 8 | operandTwo);
29
30 // Get this class.
31 jrre.api.java.lang.Class thisClass = Stack.getClassContainingMethod();
32
33 CPFieldRef fieldRef = (CPFieldRef)thisClass.getSymbol(fieldIndex);
34 CPNameType nameType = (CPNameType)thisClass.getSymbol(fieldRef.getNameType());
35
36 CPUTF8 fieldDescriptor = (CPUTF8)thisClass.getSymbol(nameType.getDescriptorIndex());
37 CPUTF8 fieldName = (CPUTF8)thisClass.getSymbol(nameType.getNameIndex());
38
39 String descriptor = fieldName.getValue()+"::"+fieldDescriptor.getValue();
40
41 // Get class containing the field.
42 CPClass cpClass = (CPClass)thisClass.getSymbol(fieldRef.getClassIndex());
43 CPUTF8 cpClassName = (CPUTF8)thisClass.getSymbol(cpClass.getNameIndex());
44
45 String className = cpClassName.getValue();
46
47 jrre.api.java.lang.Class classContainingField = MethodArea.getClass(className);
48 if(classContainingField == null){
49 return;
50 }
51
52 // fieldIndex needs to be 84
53 //System.out.println("!!GetStatic: "+descriptor+" "+classContainingField+" "+classContainingField.getStaticMemberValue(descriptor));
54 //System.out.println("ThisClass: "+thisClass);
55
56 Stack.pushOperand(classContainingField.getStaticMemberValue(descriptor));
57
58 }
59
60 public String toString(){
61 StringBuffer toReturn = new StringBuffer();
62 toReturn.append("getstatic ");
63 toReturn.append(Integer.toHexString(operandOne));
64 toReturn.append(" ");
65 toReturn.append(Integer.toHexString(operandTwo));
66 return toReturn.toString();
67 }
68 }
This page was automatically generated by Maven